//
//  LSZListOfTopicsViewController.m
//  JKFuYinProject
//
//  Created by 九酷 on 2018/8/23.
//  Copyright © 2018年 LC. All rights reserved.
//

#import "LSZListOfTopicsViewController.h"

@interface LSZListOfTopicsViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong) UITableView * tableViewList;
@property(nonatomic,strong) LSZListTopicsManager * listTopicsManager;
@end

@implementation LSZListOfTopicsViewController
-(void)getDataList
{
    __weak typeof(self) weakSelf = self;
    [LSZRequestResolutionDic getListOfTopics:@"0" :^(BOOL isOK, NSString * string, LSZListTopicsManager * manager) {
        if (isOK == YES) {
            if (manager.arrayData.count == 0) {
                weakSelf.tableViewList.mj_footer.hidden = YES;
                LSZEmptyDataVC * emptyDataVC = [[LSZEmptyDataVC alloc]init];
                [emptyDataVC showWithView:weakSelf.tableViewList];
            }
            self.listTopicsManager = manager;
            [self.tableViewList reloadData];
        }else{
            [self initWithtring:string];
        }
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"话题";
    [self.tableViewList registerClass:[LSZTopicTableViewCell class] forCellReuseIdentifier:@"LSZTopicTableViewCell"];
    [self getDataList];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.listTopicsManager.arrayData.count > indexPath.row) {
        LSZListTopicsMg * mg = nil;
        mg = self.listTopicsManager.arrayData[indexPath.row];
        CGFloat heightImage = [LSZSpecialPackaging initWithReturnsthesizeOf:60 :5];
        CGFloat size = [LSZSpecialPackaging initWithReturnsthesizeOf:17 :0.5];
        CGFloat heightTitle = [LSZSpecialPackaging caculateHeightOfText:ScreenWidth-heightImage-40 height:ScreenHeight font:size :mg.content]-20;
        CGFloat height = [LSZSpecialPackaging initWithReturnsthesizeOf:58+heightTitle :5];
        return height;
     }
    return 0.0001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.0001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.0001;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.listTopicsManager.arrayData.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LSZTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZTopicTableViewCell" forIndexPath:indexPath];
    if (self.listTopicsManager.arrayData.count > indexPath.row) {
        LSZListTopicsMg * mg = nil;
        mg = self.listTopicsManager.arrayData[indexPath.row];
        cell.listTopicsMg = mg;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.listTopicsManager.arrayData.count > indexPath.row) {
        LSZListTopicsMg * mg = nil;
        mg = self.listTopicsManager.arrayData[indexPath.row];
        LSZDynamicRealTimeSelectionVC * vc = [[LSZDynamicRealTimeSelectionVC alloc]init];
        vc.kind = mg.cate;
        vc.theme = mg.id_id;
        vc.themeStr = mg.content;
        vc.cname = mg.cname;
        vc.images = [[NSArray alloc]initWithObjects:mg.img, nil];
        vc.typeDescription = mg.content;
        [self.navigationController pushViewController:vc animated:YES];
    }
}
-(UITableView *)tableViewList
{
    if (_tableViewList == nil) {
        _tableViewList = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) style:UITableViewStyleGrouped];
        _tableViewList.delegate = self;
        _tableViewList.dataSource = self;
        _tableViewList.separatorColor = divider;
        _tableViewList.estimatedRowHeight =0;
        _tableViewList.estimatedSectionFooterHeight =0;
        _tableViewList.estimatedSectionHeaderHeight =0;
        CGFloat heightImage = [LSZSpecialPackaging initWithReturnsthesizeOf:40 :5];
        _tableViewList.separatorInset = UIEdgeInsetsMake(0, heightImage+20, 0, 10);
        [self.view addSubview:_tableViewList];
    }
    return _tableViewList;
}

@end
